package com.jiazhong.mingxing.boot.boot07.controller;

import com.jiazhong.mingxing.boot.boot07.bean.User;
import com.jiazhong.mingxing.boot.boot07.service.UserService;
import com.jiazhong.mingxing.boot.boot07.util.JsonResult;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RequestMapping("/auth")
@RestController
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    public JsonResult login(User user) {
        return userService.login(user);
    }

    // 通过参数传递token
   /* @GetMapping("/is_login")
    public JsonResult isLogin(@RequestParam("token") String token) {
        return userService.isLogin(token);
    }*/

    // 标准写法：通过头传递参数
    @GetMapping("/is_login")
    public JsonResult isLogin(HttpServletRequest request) {
        return userService.isLogin(request.getHeader("token"));
    }
}
